#include "prep_img_ipp.h"

/**
 * 预处理图像用于深度学习推理
 * @param images 输入图像向量
 * @param target_width 目标宽度
 * @param target_height 目标高度  
 * @param mean_val 归一化均值
 * @return 预处理后的图像向量
 */
std::vector<cv::Mat> preprocess_image(
    std::vector<cv::Mat>& images,
    const int target_width,
    const int target_height,
    const cv::Scalar& mean_val = cv::Scalar(0, 0, 0))
{
    std::vector<cv::Mat> preprocessed_images;

    for (const auto& img : images) {
        cv::Mat letterbox_img;
        int col = img.cols;
        int row = img.rows;
        int _max = MAX(col, row);
        letterbox_img = cv::Mat::zeros(_max, _max, CV_8UC3);
        img.copyTo(letterbox_img(cv::Rect(0, 0, col, row)));

        cv::Mat blob = cv::dnn::blobFromImage(
            letterbox_img, 1.0 / 255.0,
            cv::Size(target_width, target_height),
            mean_val, true);
        preprocessed_images.push_back(blob);
    }

    return preprocessed_images;
}